#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

#define MAXN 100000+5

int N, K;
int COW[MAXN][30];
int ans;
map<int, vector<int> > MAP;

#define H 100007

bool allsame(int x) {
	for (int i=0; i<K-1; i++) {
		if (COW[x][i] != COW[x][i+1]) return false;
	}
	return true;
}

bool same2(int x, int y) {
	for (int i=0; i<K; i++) {
		if (COW[x][i] != COW[y][i]) return false;
	}
	return true;
}

int gethash(int x) {
	int h = 0;
	for (int i=0; i<K; i++) {
		h = (h+COW[x][i]) % H;
	}
	return h;
}

void search(int x) {
	int h = gethash(x);
	vector<int> v = MAP[h];
	for (int i=0; i<v.size(); i++) {
		//printf("%d %d\n", x, v[i]);
		if (same2(x, v[i])) {
			//printf("#%d %d\n", x, v[i]);
			if (x - v[i] > ans) {
				ans = x - v[i];
			}
			return;
		}
	}
	MAP[h].push_back(x);
}

int main() {
	ans = 0;
	//freopen("1.in", "r", stdin);
	scanf("%d%d", &N, &K);
	for (int i=1; i<=N; i++) {
		int a;
		scanf("%d", &a);
		for (int j=0; j<K; j++) {
			int t = (a >> j) & 0x1;
			if (t) {
				COW[i][j] = 1;
			}
		}
	}
	for (int i=1; i<=N; i++) {
		for (int j=0; j<K; j++) {
			COW[i][j] += COW[i-1][j];
		}
		//printf("%d: %d\n", i, COW[i][0]);
	}
	for (int i=1; i<=N; i++) {
		for (int j=0; j<K; j++) {
			COW[i][j] = COW[i][j] - COW[i][K-1];
		}
		//printf("%d: %d %d %d\n", i, COW[i][0], COW[i][1], COW[i][2]);
	}
	
	for (int i=0; i<=N; i++) {
		search(i);
	}
	
	
	printf("%d\n", ans);
	return 0;
}
